home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-04-14 | 30.3 KB | 1,232 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC.cp
- // Copyright © 1984-97 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __CTidyHeap_AC__
- #include "CTidyHeap_AC.h"
- #endif
-
- #if qTidyHeap
-
- // Toolbox
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
- #ifndef __SEGLOAD__
- #include <SegLoad.h>
- #endif
- #ifndef __PROCESSES__
- #include <Processes.h>
- #endif
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- // standard libs
- #ifndef _STDARG
- #include <stdarg.h>
- #endif
- #ifndef _STRING
- #include <string.h>
- #endif
- #ifndef _STDIO
- #include <stdio.h>
- #endif
-
- // TidyHeap
-
-
- #ifndef __CTidyHeapDebugStrLogger_AC__
- #include "CTidyHeapDebugStrLogger_AC.h"
- #endif
- #ifndef __CTidyHeapAction_AC__
- #include "CTidyHeapAction_AC.h"
- #endif
- #ifndef __CTidyHeapActions_AC__
- #include "CTidyHeapActions_AC.h"
- #endif
- #ifndef __CTidyHeapActionsMore_AC__
- #include "CTidyHeapActionsMore_AC.h"
- #endif
- #ifndef __CTidyHeapActionList_AC__
- #include "CTidyHeapActionList_AC.h"
- #endif
- #ifndef __CTidyHeapBlock_AC__
- #include "CTidyHeapBlock_AC.h"
- #endif
- #ifndef __CTidyHeapBlockList_AC__
- #include "CTidyHeapBlockList_AC.h"
- #endif
- #ifndef __CTidyHeapFile_AC__
- #include "CTidyHeapFile_AC.h"
- #endif
- #ifndef __CTidyHeapLogFileLogger_AC__
- #include "CTidyHeapLogFileLogger_AC.h"
- #endif
- #ifndef __CTidyHeap_ACPRIVATE__
- #include "CTidyHeapPrivate_AC.h"
- #endif
- #ifndef __CTidyHeapState_AC__
- #include "CTidyHeapState_AC.h"
- #endif
-
- #ifndef __CActIncrementalNewFailer_AC__
- #include "CActIncrementalNewFailer_AC.h"
- #endif
-
- // TidyHeapSharedLib
-
- #ifndef __TIDYHEAPLIB__
- #include "TidyHeapSharedLib.h"
- #endif
-
-
- static const long kHeaderSize = sizeof(BlockHeader) - sizeof(long);
- static const long kTrailerSize = sizeof(BlockTrailer);
-
- void* operator new(size_t, void* ptr);
- // for some reason I had to declare this. Hmm.
-
- GlobalNewProc CTidyHeap_AC::GlobalNew;
- GlobalDeleteProc CTidyHeap_AC::GlobalDelete;
-
- CTidyHeap_AC* CTidyHeap_AC::fgSelf;
-
-
- //========================================================================================
- // NEW / DELETE Overrides.
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // operator new
- //----------------------------------------------------------------------------------------
-
- void* operator new(size_t /*size*/, void* ptr, const char* /*file*/ , short /*lineNum*/)
- {
- return ptr;
- }
-
- //----------------------------------------------------------------------------------------
- // operator new
- //----------------------------------------------------------------------------------------
-
- void* operator new(size_t /*size*/, void* ptr)
- {
- return ptr;
- }
-
- //----------------------------------------------------------------------------------------
- // operator new
- //----------------------------------------------------------------------------------------
-
- void* operator new(size_t size)
- {
- CTidyHeap_AC* tidyHeap = CTidyHeap_AC::Instance();
- return tidyHeap->CreateBlock(size, NULL, -1) ;
- }
-
- //----------------------------------------------------------------------------------------
- // operator new
- //----------------------------------------------------------------------------------------
-
- void* operator new(size_t size, const char* file, short line)
- {
- CTidyHeap_AC* tidyHeap = CTidyHeap_AC::Instance();
- return tidyHeap->CreateBlock(size, file, line);
- }
-
- //----------------------------------------------------------------------------------------
- // operator delete
- //----------------------------------------------------------------------------------------
-
- void operator delete(void* ptr )
- {
- if(ptr)
- {
- CTidyHeap_AC* tidyHeap = CTidyHeap_AC::Instance();
- tidyHeap->RemoveBlock(ptr);
- }
- }
-
- //========================================================================================
- // class CTidyHeap_AC
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC constructor
- //----------------------------------------------------------------------------------------
-
- CTidyHeap_AC::CTidyHeap_AC()
- : fCount(0),
- fSizeTally(0),
- fDebugTally(0),
- fDeleteCount(0),
- fErr(0),
- fNextNewFails(false),
- fEnabledOnStart(false),
- fLogger(NULL),
- fSettingsFile(NULL),
- fLineNum(0)
- {
- fFileName[0] = '\0';
- fLogString[0] = '\0';
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC ITidyHeap
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::ITidyHeap()
- {
- SetToLogFileLogger();
-
- fSettingsFile = new CTidyHeapFile_AC;
- if(fSettingsFile)
- {
- fSettingsFile->SetTypeAndCreator(kSettingsFileType, kSettingsFileCreator);
- fSettingsFile->AppendExtension(".prf");
- fSettingsFile->ReadObject( *this );
- }
-
- fEnabledOnStart = fPrefs.TestFlag(kEnabled);
-
- InstallPrefActions();
-
- TIDYHEAPSHAREDLIB_SETCALLBACK( Terminate );
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC destructor
- //----------------------------------------------------------------------------------------
-
- CTidyHeap_AC::~CTidyHeap_AC()
- {
- DeleteActions(fDeleteActions);
- DeleteActions(fNewActions);
- DeleteActions(fTerminationActions);
-
- fSettingsFile->WriteObject( *this );
- delete fSettingsFile;
-
- if(fLogger) delete fLogger;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetBlockCount
- //----------------------------------------------------------------------------------------
-
- long CTidyHeap_AC::GetBlockCount() const
- {
- if(fgSelf)
- return fgSelf->fBlockList.GetCount();
- else
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::FindTrailer
- //----------------------------------------------------------------------------------------
-
- BlockTrailer* CTidyHeap_AC::FindTrailer(BlockHeader* inBlock)
- {
- BlockTrailer* outPtr = (BlockTrailer*)
- (((char*)inBlock) + sizeof(BlockHeader) + inBlock->fBlockPtr->fSize - sizeof(long));
-
- if(outPtr->fMarker3 != kMarker3)
- {
- outPtr = NULL;
- fErr = kBadMarker3;
- }
-
- if(fErr)
- {
- LogError();
- }
-
- return outPtr;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::CreateBlock
- //----------------------------------------------------------------------------------------
-
- void* CTidyHeap_AC::CreateBlock(size_t size, const char* file, short line)
- {
- void* outPtr = NULL;
-
- if( !IsEnabled() )
- outPtr = GlobalNew(size);
- else
- {
- fCount++; // this is always incremented.
-
- if(fNextNewFails)
- {
- fNextNewFails = false;
-
- if(!outPtr)
- HandleNilAllocation();
- }
- else
- {
-
- BlockHeader* headerPtr = (BlockHeader*) GlobalNew(size + kHeaderSize + kTrailerSize);
- if(headerPtr)
- {
-
- CTidyHeapBlock_AC* blockPtr = CreateBlockObject();
- if(!blockPtr)
- {
- GlobalDelete( (void*) headerPtr );
- }
- else
- {
- // Setup header
- new(headerPtr) BlockHeader; // call blocks' constructor
-
- // Setup trailer
- new(((char*)headerPtr) + kHeaderSize + size) BlockTrailer;
-
- outPtr = &(headerPtr->fData);
- fDebugTally += kHeaderSize;
- fSizeTally += size;
-
- blockPtr->fSize = size;
- blockPtr->fAddress = outPtr;
- blockPtr->fHeader = headerPtr;
- blockPtr->fId = fCount;
-
- headerPtr->fBlockPtr = blockPtr;
-
- if(file)
- {
- ::strcpy( blockPtr->fFile, file );
- blockPtr->fLineNum = line;
- }
- else
- if(::strlen(fFileName))
- {
- ::strcpy( blockPtr->fFile, fFileName );
- blockPtr->fLineNum = fLineNum;
- fFileName[0] = '\0';
- fLineNum = 0;
- }
-
- CTidyHeapAction_AC* action = fNewActions.GetHead();
-
- while(action)
- {
- DoAction( action, headerPtr );
- action = action->Next();
- }
-
- if(fNextNewFails)
- {
- fNextNewFails = false;
- delete blockPtr;
- fgSelf->GlobalDelete(headerPtr);
- outPtr = NULL;
-
- if(!outPtr)
- HandleNilAllocation();
- }
- else
- if(!blockPtr->IsExempt())
- {
- // exempting a block means don't track it
- fBlockList.Append(blockPtr);
- }
-
- }
- }
- }
- }
- return outPtr;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::FindHeader
- //----------------------------------------------------------------------------------------
-
-
- BlockHeader* CTidyHeap_AC::FindHeader(char* inPtr)
- {
- fErr = 0;
-
- BlockHeader* outHeader = NULL;
-
- if(GetFeaturePrefs().TestFlag(kPointersLivesInAppHeap))
- {
- if(!PtrInAppHeap(inPtr))
- {
- fErr = kPtrNotInAppHeap;
- }
- }
-
- if(!fErr)
- {
- // First place to check for the header is immediately on top of the incoming ptr.
- char* walker = inPtr;
-
- walker -= kHeaderSize;
-
- if(CharPtrToLong(walker) == kMarker1)
- {
- outHeader = (BlockHeader*) walker;
-
- if(outHeader->fMarker2 != kMarker2)
- {
- outHeader = NULL;
-
- fErr = kBadMarker2;
- }
- }
- else
- {
- // If we get here that means the block is either corrupted
- // or the compiler has padded something. So now were going
- // to search backward for one of our markers.
-
- char* startOfValidMem = (inPtr - kHeaderSize);
- // I'm assuming that the header is there and that we have a block of mem
- // at least the sizeof the blockheader to search in. I can't guarentee that
- // mem at location less that startofValidMem is even there.
-
- for(walker = inPtr; walker >= startOfValidMem; walker--)
- {
- if(CharPtrToLong(walker) == kMarker2)
- {
- // whoo hoo! We found the footMarker.
-
- walker -= sizeof( BlockHeader ) - sizeof(long);
-
- if(CharPtrToLong(walker) == kMarker1)
- {
- outHeader = (BlockHeader*) walker;
-
- }
- else
- fErr = kBadMarker1;
-
- break;
- }
- else
- if(CharPtrToLong(walker) == kMarker1)
- {
- // whoo hoo! We found the headMarker.
-
- outHeader = (BlockHeader*) walker;
-
- if(outHeader->fMarker2 != kMarker2)
- {
- outHeader = NULL;
- }
- else
- fErr = kBadMarker2;
-
- break;
- }
-
-
- }
-
- if(!outHeader && !fErr)
- {
- fErr = kNoMarkersFound; // yikes!
- }
-
- #if qDebugTidyHeap
- if(outHeader)
- {
- long offset = ((char*)outHeader) - inPtr;
- Logf("### Had to search header for markers. Found the offset at %d", offset);
- }
- #endif
-
-
- } // else
-
- }
-
- if(fErr)
- LogError();
-
- return outHeader;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::LogError
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::LogError()
- {
-
- const char* descStr;
-
- switch(fErr)
- {
- // Should probably load these strings from a resource.
-
- case kNoErr:
- descStr = "No Error";
- break;
-
- case kBadMarker1:
- descStr = "Bad Block Header: Marker 1 corrupt";
- break;
-
- case kBadMarker2:
- descStr = "Bad Block Header: Marker 2 corrupt";
- break;
-
- case kBadMarker3:
- descStr = "Bad Block Trailer: Marker 1 corrupt";
- break;
-
- case kNoMarkersFound:
- descStr = "Found no markers at all! (Yikes!)";
- break;
-
- case kPtrCrossRefFailed:
- descStr = "Pointer Cross Reference failed.";
- break;
-
- case kPtrNotInAppHeap:
- descStr = "Block not in Application Heap.";
- break;
-
- default:
- descStr = "Invalid Error value. Run for your life!";
- break;
-
- }
-
- if(GetFeaturePrefs().TestFlag(kWarnings))
- {
- Warnf("TidyHeap Error: %s (%d)", descStr, fErr );
- }
-
- Logf("### TidyHeap Error: %s (%d)", descStr, fErr );
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::RemoveBlock
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::RemoveBlock(void* ptr)
- {
- if(!IsEnabled())
- GlobalDelete(ptr);
- else
- {
- fDeleteCount++;
-
- fErr = 0;
-
- // This will log an error if it fails.
- BlockHeader* toDelete = FindHeader((char*) ptr);
-
- if(toDelete && !fErr)
- {
- BlockTrailer* trailer = FindTrailer(toDelete);
-
- CTidyHeapBlock_AC* blockPtr = toDelete->fBlockPtr;
-
- if(trailer && !fErr)
- {
- CTidyHeapAction_AC* action = fDeleteActions.GetHead();
-
- while(action)
- {
- DoAction( action, toDelete);
- action = action->Next();
- }
-
- CTidyHeapAction_AC* deleteAction = toDelete->fBlockPtr->fDeleteAction;
-
- if(deleteAction)
- {
- DoAction( deleteAction, toDelete);
-
- delete deleteAction;
- toDelete->fBlockPtr->fDeleteAction = NULL;
- }
-
- if(blockPtr->fFlags.TestFlag(CTidyHeapBlock_AC::kDeleted))
- {
- Logf("### Block Double Delete detected!");
- Warnf("Block Double Delete detected!");
- // add more here
- }
- else
- {
- blockPtr->fFlags.SetFlag(CTidyHeapBlock_AC::kDeleted, true);
-
- if(!blockPtr->fFlags.TestFlag(CTidyHeapBlock_AC::kDontDelete))
- {
- fBlockList.Remove(blockPtr);
-
- GlobalDelete((char*)toDelete);
-
- delete blockPtr;
- }
- }
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::PushInfo
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::PushInfo(const char* file, short lineNum)
- {
- fgSelf->fLineNum = lineNum;
- ::strcpy(fgSelf->fFileName, file);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::Instance
- //----------------------------------------------------------------------------------------
-
- CTidyHeap_AC* CTidyHeap_AC::Instance()
- {
- static Boolean firstTime = true;
-
- if(firstTime)
- {
- firstTime = false;
-
- CTidyHeap_AC::GlobalNew = (GlobalNewProc) NewPtr;
- CTidyHeap_AC::GlobalDelete = (GlobalDeleteProc) DisposePtr;
-
- fgSelf = CreateTidyHeap();
- if( !fgSelf )
- {
- DebugStr("\pUnable to allocate TidyHeap. Something is seriously wrong.");
- ExitToShell();
- }
- fgSelf->ITidyHeap();
- }
-
- return fgSelf;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::Terminate
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::Terminate()
- {
- if(fgSelf)
- {
- fgSelf->HandleTermination();
-
- delete fgSelf;
- fgSelf = NULL;
-
- #if qDebugTidyHeap
- char str[100];
-
- if(MTidyHeapAllocator_AC::fgAllocationCounter > 0)
- {
- sprintf(str, "Number of TidyHeap's Leaks: %ld;g", MTidyHeapAllocator_AC::fgAllocationCounter);
- c2pstr(str);
- DebugStr((StringPtr)str);
- }
- #endif
- }
-
- }
-
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::Logf
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::Logf(const char* format, ...)
- {
- if(IsEnabled() && fLogger)
- {
- static va_list args;
-
- va_start(args, format);
- vsprintf(fLogString, format, args);
- va_end(args);
-
- fLogger->Log(fLogString);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::Warnf
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::Warnf(const char* format, ...)
- {
- static va_list args;
-
- if(IsEnabled() && GetWantsWarnings())
- {
- va_start(args, format); // can't globally scope
- ::vsprintf(fLogString, format, args);
- va_end(args); // can't globally scope
-
- ::c2pstr(fLogString);
-
- ::DebugStr((unsigned char*) fLogString);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::VerifyAllBlocks
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::VerifyAllBlocks(Boolean logBlockData)
- {
- if(IsEnabled())
- {
- long size = 0;
- if(!fBlockList.IsEmpty())
- {
- CTidyHeapBlock_AC* walker = fBlockList.GetHead();
-
- while(walker)
- {
-
- VerifyBlock( walker->fAddress, logBlockData );
- size += walker->fSize;
-
- walker = walker->Next();
- }
-
- Logf("### Sum of outstanding block sizes = %ld bytes.", size );
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::VerifyBlock
- //----------------------------------------------------------------------------------------
-
- CTidyHeapError_AC CTidyHeap_AC::VerifyBlock(void* inBlock, Boolean logBlockData)
- {
- if(IsEnabled())
- {
- CTidyHeapBlock_AC* block = 0;
- BlockHeader* header = FindHeader((char*) inBlock);
- BlockTrailer* trailer = NULL;
-
- if(header && !fErr)
- trailer = FindTrailer(header);
-
- if(!fErr)
- {
- block = header->fBlockPtr;
-
- if( (block->fAddress != inBlock) || (block->fHeader != header))
- {
- fErr = kPtrCrossRefFailed;
- }
- else
- if( logBlockData )
- block->LogBlockData();
- }
-
- if(fErr)
- {
- // already logged the error in FindHeader or FindTrailer
- if(block) block->LogBlockData();
- }
- }
-
- return fErr;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::SetDebugStrHook
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::SetToDebugStrLogger( Boolean doHalt)
- {
- AquireLogger( new CTidyHeapDebugStrLogger_AC(doHalt) );
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::SetLogFileHook
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::SetToLogFileLogger()
- {
- AquireLogger( new CTidyHeapLogFileLogger_AC );
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::VerifyState
- //----------------------------------------------------------------------------------------
-
- long CTidyHeap_AC::VerifyState(CTidyHeapState_AC &inShot)
- {
- long count = 0;
-
- if(IsEnabled())
- {
- BlockHeader* marker = FindHeader( (char*) inShot.fMarker );
-
- if( marker->fBlockPtr != fBlockList.GetTail())
- {
- Logf("### Warning: outstanding blocks remaining after state saved.");
-
- CTidyHeapBlock_AC* walker = marker->fBlockPtr->Next();
-
- while(walker)
- {
- VerifyBlock( walker->fAddress );
- count++;
- walker = walker->Next();
- }
-
- Logf("### Num new blocks since state saved: %ld", count);
- }
- else
- {
- Logf("### State detected no leaks.");
- }
- }
-
- return count;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::DeleteActions
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::DeleteActions( CTidyHeapActionList_AC &inList )
- {
- // Note:this should be a list method.
-
- CTidyHeapAction_AC* walker = inList.GetHead();
- CTidyHeapAction_AC* deleter = NULL;
-
- while(walker)
- {
- deleter = walker;
- walker = walker->Next();
-
- if(deleter)
- {
- inList.Remove(deleter);
- delete deleter;
- }
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::DoAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::DoAction( CTidyHeapAction_AC* action, BlockHeader* header)
- {
- if(header)
- {
- action->DoAction(header->fBlockPtr);
- }
- else
- {
- action->DoAction(NULL);
- }
- }
-
-
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetBlock
- //----------------------------------------------------------------------------------------
-
- CTidyHeapBlock_AC* CTidyHeap_AC::GetBlock(void* inPtr)
- {
-
- CTidyHeapBlock_AC* outBlock = NULL;
-
- if(IsEnabled())
- {
- fErr = 0;
-
-
- BlockHeader* header = FindHeader((char*) inPtr);
- if(header)
- {
- outBlock = header->fBlockPtr;
- }
- }
- return outBlock;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetMarker
- //----------------------------------------------------------------------------------------
-
- CTidyHeapMarker_AC CTidyHeap_AC::GetMarker( void* inPtr, short markerNum )
- {
- fErr = 0;
- CTidyHeapMarker_AC outMarker = 0xF0F0F0F0;
-
- if(IsEnabled())
- {
- BlockHeader* header = FindHeader((char*)inPtr);
- if(header)
- {
- switch( markerNum )
- {
- case 1:
- outMarker = header->fMarker1;
- break;
-
- case 2:
- outMarker = header->fMarker2;
- break;
-
- case 3:
- BlockTrailer* trailer = FindTrailer(header);
- if(!fErr)
- {
- outMarker = trailer->fMarker3;
- }
-
- break;
-
- }
- }
- }
- return outMarker;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::CreateBlockObject
- //----------------------------------------------------------------------------------------
-
- CTidyHeapBlock_AC* CTidyHeap_AC::CreateBlockObject()
- {
- return new CTidyHeapBlock_AC;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::MakeNextNewFail
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::MakeNextNewFail()
- {
- fNextNewFails = true;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::AquireNewAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::AquireNewAction( CTidyHeapAction_AC* inAction )
- {
- fNewActions.Append(inAction);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::RemoveNewAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::RemoveNewAction( CTidyHeapAction_AC* inAction)
- {
- fNewActions.Remove(inAction);
- }
-
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::AquireDeleteAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::AquireDeleteAction( CTidyHeapAction_AC* inAction)
- {
- fDeleteActions.Append(inAction);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::RemoveDeleteAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::RemoveDeleteAction( CTidyHeapAction_AC* inAction )
- {
- fDeleteActions.Remove(inAction);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::AquireTerminationAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::AquireTerminationAction( CTidyHeapAction_AC* inAction )
- {
- fTerminationActions.Append(inAction);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::RemoveTerminationAction
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::RemoveTerminationAction( CTidyHeapAction_AC* inAction)
- {
- fTerminationActions.Remove(inAction);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetTerminationActionList
- //----------------------------------------------------------------------------------------
-
- CTidyHeapActionList_AC& CTidyHeap_AC::GetTerminationActionList()
- {
- return fTerminationActions;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetNewActionsList
- //----------------------------------------------------------------------------------------
-
- CTidyHeapActionList_AC& CTidyHeap_AC::GetNewActionsList()
- {
- return fNewActions;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetDeleteActionList
- //----------------------------------------------------------------------------------------
-
- CTidyHeapActionList_AC& CTidyHeap_AC::GetDeleteActionList()
- {
- return fDeleteActions;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::IsEnabled
- //----------------------------------------------------------------------------------------
-
- Boolean CTidyHeap_AC::IsEnabled() const
- {
- return fEnabledOnStart;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::SetIsEnabled
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::SetIsEnabled(Boolean isEnabled)
- {
- CTidyHeapSettings_AC::SetIsEnabled(isEnabled);
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::AquireLogger
- //----------------------------------------------------------------------------------------
-
- CTidyHeapLogger_AC * CTidyHeap_AC::AquireLogger( CTidyHeapLogger_AC *inLogger, Boolean deletePrevious)
- {
- CTidyHeapLogger_AC *outLogger = NULL;
-
- if(fLogger)
- {
- if(deletePrevious)
- delete fLogger;
- else
- outLogger = fLogger;
- }
-
- fLogger = inLogger;
-
- return outLogger;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::RemoveAllActions
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::RemoveAllActions()
- {
- DeleteActions( fNewActions );
- DeleteActions( fDeleteActions );
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::InstallPrefActions
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::InstallPrefActions()
- {
- for(short i = 0; i < kNumActions; i++)
- {
- switch(i)
- {
- case kDoubleDeleteWatcher:
- if( fActions.TestFlag(i) )
- AquireDeleteAction( new CActionDoubleDeleteWatcher_AC );
- break;
-
- case kMakeNewFail:
- if( fActions.TestFlag(i) )
- AquireNewAction( new CActionMakeNewFail_AC(fNewFailCount) );
- break;
-
- case kIncrementalFailer:
- if( fActions.TestFlag(i) )
- AquireNewAction( new CActionIncrementalNewFailer_AC );
- break;
-
- case kNewVerifyAction:
- if( fActions.TestFlag(i) )
- AquireNewAction( new CActionVerifyBlock_AC );
- break;
-
- case kDeleteVerifyAction:
- if( fActions.TestFlag(i) )
- AquireDeleteAction( new CActionVerifyBlock_AC );
- break;
-
- case kNewVerifyAllAction:
- if( fActions.TestFlag(i) )
- AquireNewAction(new CActionVerifyAll_AC );
- break;
-
- case kDeleteVerifyAllAction:
- if( fActions.TestFlag(i) )
- AquireDeleteAction(new CActionVerifyAll_AC );
- break;
-
- case kExemptUnknownBlocks:
- if( fActions.TestFlag(i) )
- AquireNewAction(new CActionExcemptUnknownBlocks_AC );
- break;
-
- case kGarbageIn:
- if( fActions.TestFlag(i) )
- AquireNewAction(new CActionGarbageIn_AC );
- break;
-
- case kGarbageOut:
- if( fActions.TestFlag(i) )
- AquireDeleteAction(new CActionGarbageOut_AC );
- break;
-
- case kNewBreakOnUnknownBlock:
- if( fActions.TestFlag(i) )
- AquireNewAction(new CActionBreakOnUnknownBlock_AC );
- break;
-
- case kDeleteBreakOnUnknownBlock:
- if( fActions.TestFlag(i) )
- AquireDeleteAction(new CActionBreakOnUnknownBlock_AC );
- break;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetSessionFileLoc
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::GetSessionFileLoc(short& vol, long &dirId)
- {
- vol = 0;
- dirId = 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::HandleNilAllocation
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::HandleNilAllocation()
- {
- // override this if you want to throw an exception or something.
-
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetErr
- //----------------------------------------------------------------------------------------
-
- CTidyHeapError_AC CTidyHeap_AC::GetErr()
- {
- return fErr;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::GetBlockList
- //----------------------------------------------------------------------------------------
-
- CTidyHeapBlockList_AC& CTidyHeap_AC::GetBlockList()
- {
- return fBlockList;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::PtrInAppHeap
- //----------------------------------------------------------------------------------------
-
- Boolean CTidyHeap_AC::PtrInAppHeap(void* inPtr)
- {
- THz appZone = ::LMGetApplZone();
- return inPtr >= &(appZone->heapData) && inPtr < appZone->bkLim;
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::HandleTermination
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::HandleTermination()
- {
- if(IsEnabled())
- {
- Logf("### TidyHeap Termination Messages:");
-
- Logf("### %d Outstanding blocks, %ld total blocks, Ave Size %f",
- GetBlockCount(),
- GetBlockCountTally(),
- GetAveSize() );
-
- Logf("### New called %d times, Delete called %d times",
- GetBlockCountTally(),
- fDeleteCount);
-
- if( GetFeaturePrefs().TestFlag( CTidyHeapSettings_AC::kUndeletedBlockWarning ) &&
- GetBlockCount())
- Warnf("TidyHeap Warning: you have %ld undeleted blocks.;g", GetBlockCount() );
-
- if( GetFeaturePrefs().TestFlag( CTidyHeapSettings_AC::kLogUndeletedBlocks ) )
- {
- VerifyAllBlocks(true); // true means log the block data
- }
-
- CTidyHeapAction_AC* actionWalker = fTerminationActions.GetHead();
-
- while(actionWalker)
- {
- DoAction(actionWalker, NULL);
- actionWalker = actionWalker->Next();
- }
-
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CTidyHeap_AC::ExemptBlockFromLeakCheck
- //----------------------------------------------------------------------------------------
-
- void CTidyHeap_AC::ExemptBlockFromLeakCheck(void* inBlock)
- {
- CTidyHeapBlock_AC* theBlock = Instance()->GetBlock(inBlock);
- if(theBlock)
- {
- theBlock->SetExempt(true);
- }
- }
-
-
-
- #endif